package com.macro.mall.portal.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.ConsultFiles;
import com.macro.mall.portal.domain.vo.PageVo;
import com.macro.mall.portal.service.IConsultFilesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/consult")
@Api(tags = "ConsultFilesController", description = "查档")
public class ConsultFilesController {

    @Autowired
    private IConsultFilesService consultFilesService;

    @ApiOperation("添加查档记录")
    @RequestMapping(value = "/addOne", method = RequestMethod.POST)
    public CommonResult addOne(@RequestBody ConsultFiles consultFiles) {
        try {
            consultFilesService.addOne(consultFiles);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(null, "添加成功");
    }

    @ApiOperation("分页查询查档记录")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public CommonResult query(@RequestBody PageVo page) {
        IPage<ConsultFiles> filesIPage = null;
        try {
            filesIPage = consultFilesService.selectBy(page.getOpenId(), page.getPage(), page.getSize());
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(filesIPage);
    }
}
